//
//  CYWenDaDiCengViewController.m
//  cyydt
//
//  Created by chu on 2019/2/13.
//  Copyright © 2019 chu. All rights reserved.
//

#import "CYWenDaDiCengViewController.h"

#import "CYCommentModel.h"

#import "CYZiXunXiangGuanGuangGaoTableViewCell.h"
#import "CYVideoDetail_CommentTableViewCell.h"
#import "CYWenDaDiCengTableViewCell.h"
#import "CYWenDaDiCengTuiJianTableViewCell.h"
#import "CYWenDaDiCengXiangGuanWenDaTableViewCell.h"
#import "CYWenDaDetailViewController.h"
#import "CYProjectDetailViewController.h"
#import "CYQuestionAndAnswerViewController.h"

@interface CYWenDaDiCengViewController ()<UITableViewDelegate, UITableViewDataSource, HPGrowingTextViewDelegate, PlatformButtonClickDelegate>

{
    CGFloat _inputViewHeight;
    BOOL _commentOrReply;
    NSNumber *huifuId;//回复评论的id
    NSNumber *userid;//回复人的id
    
    UIButton *_bottomCollectionBtn;
    UIButton *_bottomZanBtn;
    
    UIImage *_shareImage;
}

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *hotAsksArr;
@property (nonatomic, strong) NSMutableArray *commentArr;
@property (nonatomic, strong) CYProjectModel *adverModel;

@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, strong) UIView *inputView;
@property (nonatomic, strong) HPGrowingTextView *growingTextView;

@end

@implementation CYWenDaDiCengViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    IQKeyboardManager *keyboardManager =  [IQKeyboardManager sharedManager];
    keyboardManager.enable = NO;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    IQKeyboardManager *keyboardManager =  [IQKeyboardManager sharedManager];
    keyboardManager.enable = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"问答详情";
    _inputViewHeight = 50;
    if (self.questionModel.img_url.count > 0) {
        NSString *url = [self.questionModel.img_url firstObject];
        [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:url] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
            
        } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
            self->_shareImage = image;
        }];
    }
    [self getTuiJian];
    [self getComment];
    [self getHuiDaList];
    [self RightsetupNavgationItemWithpictureName:@"zxxq_gengd"];
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.bottomView];
    [self.view addSubview:self.inputView];
    [self.inputView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view).with.mas_equalTo(50);
        make.left.equalTo(self.view).with.mas_offset(0);
        make.right.equalTo(self.view).with.mas_offset(0);
        make.height.mas_equalTo(50);
    }];
    self.tableView.estimatedRowHeight = 44;
    if (@available(iOS 11.0, *)) {
        self.tableView.estimatedSectionFooterHeight = 0;
        self.tableView.estimatedSectionHeaderHeight = 0;
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self initBottomData];

}

- (void)RighttouchEvent{
    YSActionSheetView * ysSheet=[[YSActionSheetView alloc]initNYSView];
    ysSheet.delegate=self;
    [[UIApplication sharedApplication].keyWindow addSubview:ysSheet];
}

- (void) customActionSheetButtonClick:(YSActionSheetButton *) btn
{
    [self shareImageToPlatformType:btn.tag];
}

- (void)shareImageToPlatformType:(NSInteger)platformType
{
    //2:qq 3:qzone 0:weixin 1:pengyouquan
    //创建分享消息对象
    if (platformType == 2 || platformType == 3) {
        
        NSString *utf8String = self.questionModel.share_url;
        NSString *title = self.questionModel.title;
        NSString *description = self.questionModel.shareContent;
        UIImage *image = nil;
        if (!_shareImage) {
            image = [UIImage imageNamed:@"login_logo"];
        }else{
            image = _shareImage;
        }
        QQApiNewsObject *newsObj = [QQApiNewsObject
                                    objectWithURL:[NSURL URLWithString:utf8String] title:title description:description previewImageData:UIImageJPEGRepresentation(image, 1)];
        SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:newsObj];
        if (platformType == 2) {
            //将内容分享到qq
            [QQApiInterface sendReq:req];
        }else{
            //将内容分享到qzone
            [QQApiInterface SendReqToQZone:req];
        }
        
    }else{
        SendMessageToWXReq *req1 = [[SendMessageToWXReq alloc]init];
        // 是否是文档
        req1.bText =  NO;
        
        //    WXSceneSession  = 0,        /**< 聊天界面    */
        //    WXSceneTimeline = 1,        /**< 朋友圈      */
        //    WXSceneFavorite = 2,
        
        
        req1.scene = (int)platformType;
        
        //创建分享内容对象
        WXMediaMessage *urlMessage = [WXMediaMessage message];
        urlMessage.title = self.questionModel.title;//分享标题
        urlMessage.description = self.questionModel.shareContent;//分享描述
        if (!_shareImage) {
            [urlMessage setThumbImage:[UIImage imageNamed:@"login_logo"]];//分享图片,使用SDK的setThumbImage方法可压缩图片大小
        }else{
            [urlMessage setThumbImage:_shareImage];//分享图片,使用SDK的setThumbImage方法可压缩图片大小
        }
        
        //创建多媒体对象
        WXWebpageObject *webObj = [WXWebpageObject object];
        webObj.webpageUrl = self.questionModel.share_url;//分享链接
        
        //完成发送对象实例
        urlMessage.mediaObject = webObj;
        req1.message = urlMessage;
        
        //发送分享信息
        [WXApi sendReq:req1];
        
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if (self.adverModel) {
        return 5;
    }
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.adverModel) {
        if (section == 0 || section == 1 || section == 2) {
            return 1;
        }else if(section == 3){
            return self.hotAsksArr.count;
        }else{
            return self.commentArr.count;
        }
    }else{
        if (section == 0 || section == 1) {
            return 1;
        }else if(section == 2){
            return self.hotAsksArr.count;
        }else{
            return self.commentArr.count;
        }
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.adverModel) {
        if (indexPath.section == 0) {
            CYWenDaDiCengTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYWenDaDiCengTableViewCell"];
            if (!cell) {
                cell = [[NSBundle mainBundle] loadNibNamed:@"CYWenDaDiCengTableViewCell" owner:nil options:nil][0];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.model = self.questionModel;
            return cell;
        }else if(indexPath.section == 1){
            CYWenDaDiCengTuiJianTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYWenDaDiCengTuiJianTableViewCell"];
            if (!cell) {
                cell = [[NSBundle mainBundle] loadNibNamed:@"CYWenDaDiCengTuiJianTableViewCell" owner:nil options:nil][0];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.model = self.huidaModel;
            
            return cell;
        }else if(indexPath.section == 2){
            CYZiXunXiangGuanGuangGaoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYZiXunXiangGuanGuangGaoTableViewCell"];
            if (!cell) {
                cell = [[NSBundle mainBundle] loadNibNamed:@"CYZiXunXiangGuanGuangGaoTableViewCell" owner:nil options:nil][0];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.model = self.adverModel;
            
            return cell;
        }else if(indexPath.section == 3){
            CYWenDaDiCengXiangGuanWenDaTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYWenDaDiCengXiangGuanWenDaTableViewCell"];
            if (!cell) {
                cell = [[NSBundle mainBundle] loadNibNamed:@"CYWenDaDiCengXiangGuanWenDaTableViewCell" owner:nil options:nil][0];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.model = self.hotAsksArr[indexPath.row];
            
            return cell;
        }else{
            CYVideoDetail_CommentTableViewCell *cell = [CYVideoDetail_CommentTableViewCell initWithTableView:tableView Identifier:@"CYVideoDetail_CommentTableViewCell"];
            if (!cell) {
                cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_CommentTableViewCell" owner:nil options:nil][0];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            CYCommentModel *comment = self.commentArr[indexPath.row];
            cell.commentModel = comment;
            cell.block = ^(NSNumber * _Nonnull userId, NSNumber * _Nonnull commentId) {
                self->_commentOrReply = NO;
                self->huifuId = commentId;
                self->userid = userId;
                [self.growingTextView becomeFirstResponder];
                
            };
            cell.zanblock = ^(NSNumber * _Nonnull userId, NSNumber * _Nonnull commentId) {
                if ([comment.isLike integerValue] == 1) {
                    [self cancleZanWithCommentModel:comment];
                }else{
                    [self zanWithCommentModel:comment];
                }
            };
            return cell;
        }
    }else{
        if (indexPath.section == 0) {
            CYWenDaDiCengTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYWenDaDiCengTableViewCell"];
            if (!cell) {
                cell = [[NSBundle mainBundle] loadNibNamed:@"CYWenDaDiCengTableViewCell" owner:nil options:nil][0];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.model = self.questionModel;
            return cell;
        }else if(indexPath.section == 1){
            CYWenDaDiCengTuiJianTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYWenDaDiCengTuiJianTableViewCell"];
            if (!cell) {
                cell = [[NSBundle mainBundle] loadNibNamed:@"CYWenDaDiCengTuiJianTableViewCell" owner:nil options:nil][0];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.model = self.huidaModel;
            
            return cell;
        }else if(indexPath.section == 2){
            CYWenDaDiCengXiangGuanWenDaTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYWenDaDiCengXiangGuanWenDaTableViewCell"];
            if (!cell) {
                cell = [[NSBundle mainBundle] loadNibNamed:@"CYWenDaDiCengXiangGuanWenDaTableViewCell" owner:nil options:nil][0];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            cell.model = self.hotAsksArr[indexPath.row];
            return cell;
        }else{
            CYVideoDetail_CommentTableViewCell *cell = [CYVideoDetail_CommentTableViewCell initWithTableView:tableView Identifier:@"CYVideoDetail_CommentTableViewCell"];
            if (!cell) {
                cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_CommentTableViewCell" owner:nil options:nil][0];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            CYCommentModel *comment = self.commentArr[indexPath.row];
            cell.commentModel = comment;
            cell.block = ^(NSNumber * _Nonnull userId, NSNumber * _Nonnull commentId) {
                self->_commentOrReply = NO;
                self->huifuId = commentId;
                self->userid = userId;
                [self.growingTextView becomeFirstResponder];
                
            };
            cell.zanblock = ^(NSNumber * _Nonnull userId, NSNumber * _Nonnull commentId) {
                if ([comment.isLike integerValue] == 1) {
                    [self cancleZanWithCommentModel:comment];
                }else{
                    [self zanWithCommentModel:comment];
                }
            };
            return cell;
        }
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.adverModel) {
        if (indexPath.section == 0 || indexPath.section == 1 || indexPath.section == 3) {
            return UITableViewAutomaticDimension;
        }else if (indexPath.section == 2){
            return 270;
        }
        CYVideoDetail_CommentTableViewCell *cell = [CYVideoDetail_CommentTableViewCell initWithTableView:tableView Identifier:@"CYVideoDetail_CommentTableViewCell"];
        cell.commentModel = self.commentArr[indexPath.row];
        return cell.cellHeight;
    }else{
        if (indexPath.section == 0 || indexPath.section == 1 || indexPath.section == 2) {
            return UITableViewAutomaticDimension;
        }
        CYVideoDetail_CommentTableViewCell *cell = [CYVideoDetail_CommentTableViewCell initWithTableView:tableView Identifier:@"CYVideoDetail_CommentTableViewCell"];
        cell.commentModel = self.commentArr[indexPath.row];
        return cell.cellHeight;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    if (self.adverModel) {
        if (section == 0 || section == 1 || section == 2) {
            return 0.0001f;
        }
        return 40;
    }else{
        if (section == 0 || section == 1) {
            return 0.0001f;
        }
        return 40;
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor whiteColor];
    [view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    if (self.adverModel) {
        if (section == 0 || section == 1 || section == 2) {
            return view;
        }else if (section == 3){
            UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(15, 12, 2, 16)];
            view1.backgroundColor = [UIColor redColor];
            [view addSubview:view1];
            
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view1.frame) + 10, 12, 100, 16)];
            label.textColor = RGBOF(0x333333);
            label.font = [UIFont systemFontOfSize:15];
            label.text = @"相关问答";
            [view addSubview:label];
            
            UIButton *more = [UIButton buttonWithType:UIButtonTypeCustom];
            more.frame = CGRectMake(kWindowW - 70, 5, 55, 30);
            [more setTitle:@"更多 >" forState:UIControlStateNormal];
            [more setTitleColor:RGBOF(0x999999) forState:UIControlStateNormal];
            more.titleLabel.font = [UIFont systemFontOfSize:12];
            [view addSubview:more];
            [more addTarget:self action:@selector(zixunmoreAction:) forControlEvents:UIControlEventTouchUpInside];
            return view;
        }else{
            UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(15, 12, 2, 16)];
            view1.backgroundColor = [UIColor redColor];
            [view addSubview:view1];
            
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view1.frame) + 10, 12, 100, 16)];
            label.textColor = RGBOF(0x333333);
            label.font = [UIFont systemFontOfSize:15];
            label.text = [NSString stringWithFormat:@"评论%ld",self.commentArr.count];
            [view addSubview:label];
            return view;
        }
    }else{
        if (section == 0 || section == 1) {
            return view;
        }else if (section == 2){
            UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(15, 12, 2, 16)];
            view1.backgroundColor = [UIColor redColor];
            [view addSubview:view1];
            
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view1.frame) + 10, 12, 100, 16)];
            label.textColor = RGBOF(0x333333);
            label.font = [UIFont systemFontOfSize:15];
            label.text = @"相关问答";
            [view addSubview:label];
            
            UIButton *more = [UIButton buttonWithType:UIButtonTypeCustom];
            more.frame = CGRectMake(kWindowW - 70, 5, 55, 30);
            [more setTitle:@"更多 >" forState:UIControlStateNormal];
            [more setTitleColor:RGBOF(0x999999) forState:UIControlStateNormal];
            more.titleLabel.font = [UIFont systemFontOfSize:12];
            [view addSubview:more];
            [more addTarget:self action:@selector(zixunmoreAction:) forControlEvents:UIControlEventTouchUpInside];
            return view;
        }else{
            UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(15, 12, 2, 16)];
            view1.backgroundColor = [UIColor redColor];
            [view addSubview:view1];
            
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view1.frame) + 10, 12, 100, 16)];
            label.textColor = RGBOF(0x333333);
            label.font = [UIFont systemFontOfSize:15];
            label.text = [NSString stringWithFormat:@"评论%ld",self.commentArr.count];
            [view addSubview:label];
            return view;
        }
    }
}

- (void)zixunmoreAction:(UIButton *)sender{
    BOOL constaint = NO;
    for (id VC in self.navigationController.childViewControllers) {
        if ([VC isKindOfClass:NSClassFromString(@"CYQuestionAndAnswerViewController")]) {
            constaint = YES;
            [[AppDelegate sharedAppDelegate] popToViewController:(UIViewController *)VC];
            break;
        }else{
            constaint = NO;
        }
    }
    if (constaint) {
        for (id VC in self.navigationController.childViewControllers) {
            if ([VC isKindOfClass:NSClassFromString(@"CYQuestionAndAnswerViewController")]) {
                [[AppDelegate sharedAppDelegate] popToViewController:(UIViewController *)VC];
                break;
            }else{
            }
        }
    }else{
        CYQuestionAndAnswerViewController *que = [[CYQuestionAndAnswerViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:que];
    }
//    [self.tabBarController setSelectedIndex:0];
//    [self.navigationController popToRootViewControllerAnimated:NO];
//    [[NSNotificationCenter defaultCenter] postNotificationName:@"gotoZiXun" object:nil];
}

- (void)shangjiAction:(UIButton *)sender{
    [self.tabBarController setSelectedIndex:1];
    [self.navigationController popToRootViewControllerAnimated:NO];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    return view;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.adverModel) {
        if (indexPath.section == 3) {
            CYProjectModel *model = self.hotAsksArr[indexPath.row];
            CYWenDaDetailViewController *detail = [[CYWenDaDetailViewController alloc] init];
            detail.wedaId = [model.ID stringValue];
            [[AppDelegate sharedAppDelegate] pushViewController:detail];
        }
        if (indexPath.section == 2) {
            CYProjectDetailViewController *detail = [[CYProjectDetailViewController alloc] init];
            detail.model = self.adverModel;
            [[AppDelegate sharedAppDelegate] pushViewController:detail];
        }
    }else{
        if (indexPath.section == 2) {
            CYProjectModel *model = self.hotAsksArr[indexPath.row];
            CYWenDaDetailViewController *detail = [[CYWenDaDetailViewController alloc] init];
            detail.wedaId = [model.ID stringValue];
            [[AppDelegate sharedAppDelegate] pushViewController:detail];
        }
    }
}


- (void)initBottomData{
    if ([self.huidaModel.is_like integerValue] == 2) {
        //未点赞
        _bottomZanBtn.selected = NO;
    }else{
        //已点赞
        _bottomZanBtn.selected = YES;
    }
    
    if ([self.questionModel.is_collect integerValue] == 2) {
        //未收藏
        _bottomCollectionBtn.selected = NO;
    }else{
        //已收藏
        _bottomCollectionBtn.selected = YES;
    }
}

- (void)getHuiDaList{
    NSString *url = [NSString stringWithFormat:@"%@%@",HOST, @"ask/index"];
    NSDictionary *param = @{@"id":self.questionModel.ID, @"page":@"1"};
    [[XBRequest sharedInstance] getDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"获取回答列表 ---- %@",responseResult);
        if ([self.tableView.mj_header isRefreshing]) {
            [self.tableView.mj_header endRefreshing];
        }
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                
            }else{
                
            }
        }
    }];
}

- (void)getTuiJian{
    NSString *url = [NSString stringWithFormat:@"%@%@",HOST, @"recommend"];
    NSDictionary *param = @{@"id":self.questionModel.ID, @"type":@"4"};
    [[XBRequest sharedInstance] getDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"获取推荐 ---- %@",responseResult);
        if ([self.tableView.mj_header isRefreshing]) {
            [self.tableView.mj_header endRefreshing];
        }
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                NSDictionary *data = responseResult[@"data"];
                
                //广告
                if ([data[@"advertisement"] isKindOfClass:[NSDictionary class]]) {
                    NSDictionary *advertisement = data[@"advertisement"];
                    self.adverModel = [CYProjectModel mj_objectWithKeyValues:advertisement];
                }
                
                //热门资讯
                if ([data[@"hotAsks"] isKindOfClass:[NSArray class]]) {
                    NSArray *hotNews = data[@"hotAsks"];
                    if (hotNews.count > 0) {
                        [self.hotAsksArr removeAllObjects];
                        for (NSDictionary *dic in hotNews) {
                            CYProjectModel *model = [CYProjectModel mj_objectWithKeyValues:dic];
                            [self.hotAsksArr addObject:model];
                        }
                    }
                }
                [self.tableView reloadData];
            }else{
                
            }
        }
    }];
}

- (void)getComment{
    self.page = 1;
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"comments"];
    NSDictionary *param = @{@"articleId":self.huidaModel.ID, @"type":@"4", @"pageNo":@1, @"pageSize":@"10"};
    [[XBRequest sharedInstance] getDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"获取评论 ---- %@",responseResult);
        if ([self.tableView.mj_header isRefreshing]) {
            [self.tableView.mj_header endRefreshing];
        }
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                NSDictionary *data = responseResult[@"data"];
                NSDictionary *comments = data[@"comments"];
                [self.commentArr removeAllObjects];
                for (NSDictionary *dic in comments) {
                    CYCommentModel *model = [CYCommentModel modelWithDictionary:dic];
                    [self.commentArr addObject:model];
                }
                [self.tableView reloadData];
            }else{
                
            }
        }
    }];
}

- (void)getMoreComment{
    self.page ++;
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"comments"];
    NSDictionary *param = @{@"articleId":self.huidaModel.ID, @"type":@"4", @"pageNo":[NSNumber numberWithInteger:self.page], @"pageSize":@"10"};
    [[XBRequest sharedInstance] getDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"获取评论 ---- %@",responseResult);
        if ([self.tableView.mj_footer isRefreshing]) {
            [self.tableView.mj_footer endRefreshing];
        }
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
            self.page --;
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                NSDictionary *data = responseResult[@"data"];
                NSDictionary *comments = data[@"comments"];
                for (NSDictionary *dic in comments) {
                    CYCommentModel *model = [CYCommentModel modelWithDictionary:dic];
                    [self.commentArr addObject:model];
                }
                [self.tableView reloadData];
            }else{
                self.page --;
            }
        }
    }];
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, kWindowH - Height_NavBar - self.bottomView.frame.size.height) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = BackGroundColor;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [self getTuiJian];
            [self getComment];
        }];
        _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
            [self getMoreComment];
        }];

        [_tableView registerNib:[UINib nibWithNibName:@"CYZiXunXiangGuanGuangGaoTableViewCell" bundle:nil] forCellReuseIdentifier:@"CYZiXunXiangGuanGuangGaoTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"CYVideoDetail_CommentTableViewCell" bundle:nil] forCellReuseIdentifier:@"CYVideoDetail_CommentTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"CYWenDaDiCengTableViewCell" bundle:nil] forCellReuseIdentifier:@"CYWenDaDiCengTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"CYWenDaDiCengTuiJianTableViewCell" bundle:nil] forCellReuseIdentifier:@"CYWenDaDiCengTuiJianTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"CYWenDaDiCengXiangGuanWenDaTableViewCell" bundle:nil] forCellReuseIdentifier:@"CYWenDaDiCengXiangGuanWenDaTableViewCell"];
        
    }
    return _tableView;
}

- (NSMutableArray *)hotAsksArr{
    if (!_hotAsksArr) {
        _hotAsksArr = [NSMutableArray arrayWithCapacity:0];
    }
    return _hotAsksArr;
}

- (NSMutableArray *)commentArr{
    if (!_commentArr) {
        _commentArr = [NSMutableArray arrayWithCapacity:0];
    }
    return _commentArr;
}

- (UIView *)bottomView{
    if (!_bottomView) {
        _bottomView = [[UIView alloc] init];
        _bottomView.backgroundColor = [UIColor whiteColor];
        if (HX_IS_IPhoneX_All) {
            _bottomView.frame = CGRectMake(0, kWindowH - Height_NavBar - 83, kWindowW, 83);
        }else{
            _bottomView.frame = CGRectMake(0, kWindowH - Height_NavBar - 48, kWindowW, 48);
        }
        
        UIView *contrainerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, 48)];
        [_bottomView addSubview:contrainerView];
        
        UIButton *commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [commentBtn setFrame:CGRectMake(15, 9, 185, 30)];
        commentBtn.layer.cornerRadius = 15;
        commentBtn.layer.borderWidth = 1;
        commentBtn.layer.borderColor = RGBOF(0xe3e3e3).CGColor;
        commentBtn.layer.masksToBounds = YES;
        [commentBtn setBackgroundColor:RGBOF(0xf7f7f7)];
        [commentBtn setTitle:@"   写评论" forState:UIControlStateNormal];
        [commentBtn setImage:[UIImage imageNamed:@"wd_wdwd"] forState:UIControlStateNormal];
        [commentBtn setTitleColor:RGBOF(0x999999) forState:UIControlStateNormal];
        commentBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        commentBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [commentBtn setContentEdgeInsets:UIEdgeInsetsMake(0, 25, 0, 0)];
        [commentBtn addTarget:self action:@selector(commentAction) forControlEvents:UIControlEventTouchUpInside];
        [contrainerView addSubview:commentBtn];
        
        NSArray *images = @[@"ksp_pl", @"ksp_sc", @"ksp_zan"];
        CGFloat width = 20;
        CGFloat height = 20;
        for (int i = 2; i >= 0; i--) {
            UIButton *commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [commentBtn setFrame:CGRectMake(kWindowW - 25 - 20 - (2 - i) * width - (2 - i) * 25, 12, width, height)];
            [commentBtn setImage:[UIImage imageNamed:images[i]] forState:UIControlStateNormal];
            [commentBtn addTarget:self action:@selector(btnsClick:) forControlEvents:UIControlEventTouchUpInside];
            [contrainerView addSubview:commentBtn];
            commentBtn.tag = i;
            if (i == 1) {
                _bottomCollectionBtn = commentBtn;
                [commentBtn setImage:[UIImage imageNamed:@"video_collect_selected"] forState:UIControlStateSelected];
            }
            if (i == 2) {
                _bottomZanBtn = commentBtn;
                [commentBtn setImage:[UIImage imageNamed:@"zan_sel"] forState:UIControlStateSelected];
            }
        }
    }
    return _bottomView;
}

#pragma mark - 关注
- (void)guanzhu{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"attention"];
    NSDictionary *param = @{@"toUserId":self.questionModel.user_id};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"添加关注 ---- %@",responseResult);
        [EasyShowLodingView hidenLoding];
        if ([responseResult objectForKey:@"resError"]) {
            [[UIApplication sharedApplication].keyWindow makeToast:ResErrorMessage duration:1.5 position:CSToastPositionCenter];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                //                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
            }
        }
    }];
}

- (void)cancleguanzhu{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@/%@",User_HOST, @"attention", self.questionModel.user_id];
    NSDictionary *param = @{@"userId":self.questionModel.user_id};
    [[XBRequest sharedInstance] deleteDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"取消关注 ---- %@",responseResult);
        [EasyShowLodingView hidenLoding];
        if ([responseResult objectForKey:@"resError"]) {
            [[UIApplication sharedApplication].keyWindow makeToast:ResErrorMessage duration:1.5 position:CSToastPositionCenter];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                //                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
            }
        }
    }];
}

#pragma mark - 评论
- (void)commentAction{
    _commentOrReply = YES;
    [self.growingTextView becomeFirstResponder];
}

#pragma mark - 底部按钮的点赞，收藏
- (void)btnsClick:(UIButton *)sender{
    if (sender.tag == 0) {
        //评论
        [self commentAction];
    }else if (sender.tag == 1){
        //收藏
        if ([self.questionModel.is_collect integerValue] == 1) {
            //一收藏
            [self cancleCollection];
        }else{
            [self collection];
        }
    }else{
        //点赞
        if ([self.huidaModel.is_like integerValue] == 1) {
            [self cancleZanWenZhang];
        }else{
            [self zanWenZhang];
        }
    }
}

#pragma mark - 收藏取消收藏
- (void)cancleCollection{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@/%@",User_HOST, @"collection",self.questionModel.ID];
    NSDictionary *param = @{@"type":@"4", @"articleId":self.questionModel.ID};
    [[XBRequest sharedInstance] deleteDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"取消收藏 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                self.questionModel.is_collect = [NSNumber numberWithInteger:2];
                NSInteger tag = [self.questionModel.collect_number integerValue];
                self.questionModel.collect_number = [NSString stringWithFormat:@"%ld",(tag - 1)];
                [self initBottomData];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                
            }
        }
    }];
}

- (void)collection{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"collection/addCollect"];
    NSDictionary *param = @{@"type":@4, @"articleId":self.questionModel.ID};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"收藏本咨询 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                self.questionModel.is_collect = [NSNumber numberWithInteger:1];
                NSInteger tag = [self.questionModel.collect_number integerValue];
                self.questionModel.collect_number = [NSString stringWithFormat:@"%ld",(tag + 1)];
                [self initBottomData];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                
            }
        }
    }];
}

#pragma mark - 给问答赞和取消点赞
- (void)zanWenZhang{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"addLike"];
    NSDictionary *param = @{@"type":@1, @"likeId":self.huidaModel.ID, @"origin":@"4", @"toLikerId":self.huidaModel.user_id};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"给问答点赞 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                self.huidaModel.is_like = [NSNumber numberWithInteger:1];
                NSInteger tag = [self.huidaModel.like_number integerValue];
                self.huidaModel.like_number = [NSString stringWithFormat:@"%ld",(tag + 1)];
                [self initBottomData];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                
            }
        }
    }];
}
- (void)cancleZanWenZhang{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"cancleLike"];
    NSDictionary *param = @{@"type":@1, @"articleId":self.huidaModel.ID, @"origin":@"4", @"toLikerId":self.huidaModel.user_id};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"给问答取消点赞 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                self.huidaModel.is_like = [NSNumber numberWithInteger:2];
                NSInteger tag = [self.huidaModel.like_number integerValue];
                self.huidaModel.like_number = [NSString stringWithFormat:@"%ld",(tag - 1)];
                [self initBottomData];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                
            }
        }
    }];
}
#pragma mark - 给评论赞和取消点赞
- (void)cancleZanWithCommentModel:(CYCommentModel *)commentModel{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"cancleLike"];
    NSDictionary *param = @{@"type":@2, @"articleId":commentModel.ID, @"origin":@"4", @"toLikerId":commentModel.userId};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"取消点赞 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                commentModel.isLike = [NSNumber numberWithInteger:2];
                NSInteger tag = [commentModel.likeNumber integerValue];
                commentModel.likeNumber = [NSString stringWithFormat:@"%ld",(tag - 1)];
                [self.tableView reloadData];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                
            }
        }
    }];
}

- (void)zanWithCommentModel:(CYCommentModel *)commentModel{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"addLike"];
    NSDictionary *param = @{@"type":@2, @"likeId":commentModel.ID, @"origin":@"4", @"toLikerId":commentModel.userId};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"赞评论 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                commentModel.isLike = [NSNumber numberWithInteger:1];
                NSInteger tag = [commentModel.likeNumber integerValue];
                commentModel.likeNumber = [NSString stringWithFormat:@"%ld",(tag + 1)];
                [self.tableView reloadData];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
            }
        }
    }];
}

#pragma mark - 发布评论
- (void)fasongpinglunWithText:(NSString *)content{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"comment"];
    NSDictionary *param = @{@"toUserId":self.huidaModel.user_id, @"type":@"4", @"answerId":self.huidaModel.ID, @"content":content, @"articleId":self.questionModel.ID};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"发布评论 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                [self getComment];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                
            }
        }
    }];
}

#pragma mark - 发布回复
- (void)fasongHuiFuWithText:(NSString *)content{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"inserReply"];
    NSDictionary *param = @{@"toUserId":userid, @"type":@"4", @"commentId":huifuId, @"content":content};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"发布回复 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                [self getComment];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                
            }
        }
    }];
}

- (UIView *)inputView{
    if (!_inputView) {
        _inputView = [[UIView alloc] init];
        _inputView.backgroundColor = [UIColor whiteColor];
        HPGrowingTextView *group = [[HPGrowingTextView alloc] init];
        self.growingTextView = group;
        group.delegate = self;
        group.font = [UIFont systemFontOfSize:14];
        group.minNumberOfLines = 1;
        group.maxNumberOfLines = 5;
        group.placeholder = @"输入评论";
        group.returnKeyType = UIReturnKeySend;
        group.enablesReturnKeyAutomatically = YES;
        group.backgroundColor = RGBOF(0xf6f6f6);
        group.layer.cornerRadius = 5;
        [_inputView addSubview:group];
        [group mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self->_inputView).with.mas_offset(10);
            make.top.equalTo(self->_inputView).with.mas_offset(5);
            make.right.equalTo(self->_inputView).with.mas_offset(-10);
            make.bottom.equalTo(self->_inputView).with.mas_offset(-5);
            
        }];
    }
    return _inputView;
}

#pragma mark - UIKeyboardNotification

- (void)keyboardWillShow:(NSNotification *)notification
{
    CGRect endRect = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
    
    NSLog(@"keyboardWillShow -- %f",endRect.size.height);
    [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        [self.inputView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.view).with.mas_equalTo(-endRect.size.height);
            make.left.equalTo(self.view).with.mas_offset(0);
            make.right.equalTo(self.view).with.mas_offset(0);
            make.height.mas_equalTo(self->_inputViewHeight);
        }];
        [self.view layoutIfNeeded];
    } completion:nil];
}

- (void)keyboardWillHide:(NSNotification *)notification
{
    [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        [self.inputView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.view).with.mas_equalTo(self->_inputViewHeight);
        }];
        [self.view layoutIfNeeded];
    } completion:nil];
}

#pragma mark - UITextViewDelegate

- (void)growingTextView:(HPGrowingTextView *)growingTextView willChangeHeight:(float)height
{
    _inputViewHeight = height + 14;
    [self.inputView mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.height.mas_equalTo(height + 14);
    }];
    [self.view layoutIfNeeded];
}

- (BOOL)growingTextViewShouldReturn:(HPGrowingTextView *)growingTextView
{
    [self.growingTextView resignFirstResponder];
    return YES;
}

- (BOOL)growingTextView:(HPGrowingTextView *)growingTextView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    //判断是回车键就发送出去
    if ([text isEqualToString:@"\n"])
    {
        if (_commentOrReply) {
            [self fasongpinglunWithText:self.growingTextView.text];
        }else{
            [self fasongHuiFuWithText:self.growingTextView.text];
        }
        self.growingTextView.text = @"";
        [self.growingTextView resignFirstResponder];
        [self.tableView reloadData];
        return NO;
    }
    return YES;
}

- (void)growingTextViewDidChange:(HPGrowingTextView *)growingTextView
{
    UITextRange *selectedRange = growingTextView.internalTextView.markedTextRange;
    NSString *newText = [growingTextView.internalTextView textInRange:selectedRange];
    
    if (newText.length < 1)
    {
        // 高亮输入框中的@
        UITextView *textView = self.growingTextView.internalTextView;
        NSRange range = textView.selectedRange;
        
        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:textView.text];
        [string addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, string.string.length)];
        
        
        textView.attributedText = string;
        textView.selectedRange = range;
    }
}

- (void)growingTextViewDidChangeSelection:(HPGrowingTextView *)growingTextView
{
    // 光标不能点落在@词中间
    NSRange range = growingTextView.selectedRange;
    if (range.length > 0)
    {
        // 选择文本时可以
        return;
    }
    
}

@end
